<template>
  <div class="dashboard">
    <header class="dashboard-header">
      <h1>欢迎来到 MindCare AI</h1>
      <div class="user-info">
        <span>欢迎，{{ userInfo.username }}</span>
        <button @click="logout" class="logout-btn">退出登录</button>
      </div>
    </header>
    
    <main class="dashboard-content">
      <div class="welcome-card">
        <h2>心理健康AI助手</h2>
        <p>这里是您的个人心理健康管理空间，我们致力于为您提供专业的心理关怀服务。</p>
        <div class="feature-grid">
          <div class="feature-item">
            <h3>情感分析</h3>
            <p>智能分析您的情绪状态，提供个性化建议</p>
          </div>
          <div class="feature-item">
            <h3>对话机器人</h3>
            <p>24/7在线陪伴，随时倾听您的心声</p>
          </div>
          <div class="feature-item">
            <h3>专业咨询</h3>
            <p>连接专业心理咨询师，获得专业指导</p>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      userInfo: {}
    }
  },
  mounted() {
    // 从localStorage获取用户信息
    const userStr = localStorage.getItem('user')
    if (userStr) {
      this.userInfo = JSON.parse(userStr)
    }
  },
  methods: {
    logout() {
      // 清除本地存储
      localStorage.removeItem('token')
      localStorage.removeItem('retoken')
      localStorage.removeItem('user')
      
      // 跳转到登录页
      this.$router.push('/auth')
    }
  }
}
</script>

<style scoped>
.dashboard {
  min-height: 100vh;
  background: linear-gradient(135deg, #f7f4f1 0%, #e9e3db 100%);
}

.dashboard-header {
  background: #fff;
  padding: 20px 40px;
  box-shadow: 0 2px 10px rgba(140, 90, 50, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dashboard-header h1 {
  color: #7a5232;
  margin: 0;
  font-size: 1.8rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-info span {
  color: #a88b6a;
  font-weight: 500;
}

.logout-btn {
  background: #8b5c37;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.logout-btn:hover {
  background: #7a5232;
}

.dashboard-content {
  padding: 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.welcome-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 4px 32px rgba(140, 90, 50, 0.08);
  text-align: center;
}

.welcome-card h2 {
  color: #7a5232;
  margin-bottom: 20px;
  font-size: 2rem;
}

.welcome-card p {
  color: #a88b6a;
  font-size: 1.1rem;
  margin-bottom: 40px;
  line-height: 1.6;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
  margin-top: 40px;
}

.feature-item {
  background: #faf7f3;
  padding: 30px;
  border-radius: 12px;
  border: 1px solid #e0d6c8;
  transition: transform 0.2s, box-shadow 0.2s;
}

.feature-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(140, 90, 50, 0.15);
}

.feature-item h3 {
  color: #7a5232;
  margin-bottom: 15px;
  font-size: 1.3rem;
}

.feature-item p {
  color: #a88b6a;
  line-height: 1.5;
  margin: 0;
}
</style> 